
function GetMaxAtt(da) {
		if ( CDB.getCurUserOptions().pvp ) {
			return  5;	
		} else {
			return  3;
		}
	};

function GetSkipLimit(da) {
		if ( CDB.getCurUserOptions().pvp ) {
			return  15;	
		} else {
			return  6;
		}
	};

// var hnt ; 
CHuntMgr2 = function() {
	this.objName = 'CHuntMgr2 : ';
	
	this.initialize();
};


CHuntMgr2.CANNOT_FIND_PROPERDA = 20;
CHuntMgr2.ENDOF_DA_ARRAY = 21;
CHuntMgr2.LESS_SOLS_OR_CONTROL = 22;
CHuntMgr2.ENDOF_CASTLES = 23;
CHuntMgr2.ERROR = 29;


// ?�건. mgr ??
// �?  ?�는 ?�이..  
//  ?�단, taget ?? 배열�?받아??
//  target ??validation ???�인?�고, 
//  target ??1 개씩   att �??�행??
//  error cb 가 ?�라 ?�면,, cb code ??/?�라, next cast �?가?��?,,  error 보고�??�행?? 
//  over 가 모자?�면, ?�음 cstl �??�동. 
//  success cb 가 ?�면, ?�음 att �??�행.
// 
// next cstl ?�보???�기??관�?
// ?��? ?�동 ?�는??func ?�서 enxt cast �?받도�???

CHuntMgr2.prototype = {

	// hnting ?�성. 
	initialize: function() {
		var self = this;
		// Events.enable.call(self);
		
		// this.cstl = [];
		this.force_stop = false;
		// this.hnting = em.hnting;
		
		this.hnting = new CHnting();
		this.hnting.initialize();

		// for error cb from hnting 		
		em.cbs.hntingerr = $.Callbacks("unique stopOnFalse");
		em.cbs.hntingerr.add ( function(code, info) { self.errCbAttda(code, info); });
		
		// add global event cb 
		em.cbs.forcestop.add ( function() { debug.log(self,'Set ForceStop'); self.SetStop(); });
		
	},
	
/*
	setCastles: function(cstls) {
		this.cstl= cstls;
			
	},
*/
	
	// 1 da att ok !
	// go 1 more time... 
	succCbAttda: function(attinfo) {
		debug.log(em.hntmgr, ' OK 1 DA att ' );
		debug.log(em.hntmgr, ' OK 1 DA att ' );
		debug.log(em.hntmgr, ' OK 1 DA att ' );
		debug.log(em.hntmgr, ' OK 1 DA att ' );
		console.log(  'succCbAttda', attinfo, arguments[0] , arguments[1] );
		
		// DO NOT pop cur DA from DAs :: go until max 3 times 

		// go 1 more  w/ same DA 
			// report attinfo w/ endtime to cstlmgr
			this.curDA.attnum += 1;	// 
			
			// pvp specific .. endtime calc
			if (CDB.getCurUserOptions().pvp) {
				// set travelsec to endtime 
				attinfo.endtime = attinfo.traveltime;
				}
			
			// print result  well formed 
			em.cbs.hntdone.fire(attinfo);	

			var da = this.curDA;
			var infostr = da.x + '\/' + da.y + ' h:' + da.h + ' n:'+ da.n + ' att:' + da.attnum + ' sk:' + da.skipcnt
								+  ' gid:' + attinfo.h.gid + ' o:' + attinfo.trs.o +  ( (attinfo.trs.b > 0 ) ? ' b:' + attinfo.trs.b : '') 
								+  ' secs:' + attinfo.secs + ' end:' + CUtil.TimeToString(attinfo.endtime)  
								+ ' trav:' + CUtil.TimeToString(attinfo.traveltime) ;
			em.util.print_result( infostr ); 
			
			var self =this;
			 setTimeout( function() { self.attProperDA();} , CUtil.RandTime(1500));
	},
	// error type :  
	/*
CHnting.DA_INVALID = 9;
CHnting.SOL_INVALID = 10;
CHnting.FAIL_ATT_WCOST = 11;
CHnting.FAIL_ATT = 12;
CHnting.NO_HERO = 13;
CHnting.ATT_MAX = 14;
CHnting.LESS_CONTROLNUM = 15;
CHnting.FAIL_GETFAVS = 16;
	*/
	errCbAttda: function(err_code, info) {
		
		function getErrStr (err_code) {
			var errstr = 'unknown';
			switch (err_code ) {
				case CHnting.DA1ATT_DONE: 	errstr = 'OK done DA att'; break;
				case CHnting.INFORM_ATTNUM: 	errstr = 'Informed att num '; break;
				case CHnting.SOL_INVALID: 	errstr = 'NO Soldiers in Barrack'; break;
				case CHnting.FAIL_ATT_WCOST: errstr = 'FAil att with cost'; break;
				case CHnting.FAIL_ATT:		errstr = 'FAil attack'; break;
				case CHnting.NO_HERO:		errstr = 'No Hero in castle'; break;
				case CHnting.LESS_CONTROLNUM:errstr = 'Hero control num is less than ....'; break;
				case CHnting.LESS_SOLS:		errstr = 'Less Soldiers in Barrack  than ....'; break;
				
				case CHnting.DA_INVALID:	errstr = 'No DA: disappered '; break;
				case CHnting.ATT_MAX:		errstr = 'Max 3 Times attcked '; break;
				case CHnting.FAIL_GETFAVS:			errstr = 'Fail Get Favs : net error ?, key error'; break;
				case CHnting.RESEARCH_INVALID:			errstr = 'Fail RESEARCH_INVALID  ExAR < 10 '; break;
				
			}
			return errstr;
		}
		
		debug.log(em.hntmgr, 'got err:' + err_code + ' :'+ getErrStr(err_code));
		
		switch(err_code) {

			case CHnting.DA1ATT_DONE:
				debug.log( this,  ' ~done', err_code, arguments[0] , arguments[1] , arguments[2]);
				// this.alterDA_skip = 0;	// reset skip count 
				this.succCbAttda(info);	// attinfo
				 
			break;
			
			case CHnting.INFORM_ATTNUM:
				debug.log( this,  ' got attnum ', info , ' add cur try +1');

				// update da attnum 
				this.curDA.attnum = info  ;	// 
			break;
			
			case CHnting.SOL_INVALID:
			case CHnting.FAIL_ATT_WCOST:
			case CHnting.FAIL_ATT:
			case CHnting.NO_HERO:
			
				em.hntmgr.doneCstlHnt(err_code);
			break;
			
			
			// new att way
			case CHnting.LESS_CONTROLNUM:
			case CHnting.LESS_SOLS:

				// 이거 모두 변경..  automatically move from 6, to 5, 4,3 .. and pop DA. from DAsARr 
				// go with alter DA 
				debug.log(em.hntmgr, ' RE try with attProperDA DA  :: Alter DA Skip cnt ' );
				setTimeout( function() { em.hntmgr.attProperDA.call(em.hntmgr);} ,CUtil.RandTime(1000));	
			
				
			break;
			
			case CHnting.DA_INVALID:
				debug.log(em.hntmgr, ' NO DA , disappred   =>  go next attProperDA  ' );
				this.curDA.disappered = true;
				// fall throught !!
			case CHnting.ATT_MAX:			// 3 초과 

				debug.log(em.hntmgr, ' Max atted  =>  go next attProperDA  ' );
				this.curDA.attnum =  GetMaxAtt();//3;
				setTimeout( function() { em.hntmgr.attProperDA.call(em.hntmgr);} ,CUtil.RandTime(1500));	
				break;
			
			// network error ?? 
			case CHnting.FAIL_GETFAVS:
			case CHnting.RESEARCH_INVALID: 	// stop right now
					// abort 
				debug.log(em.hntmgr, ' Get sevear error : network error ??? , research lv error ?? ' );
				em.hntmgr.doneCstlHnt(err_code);
			break;			
		}
	},
	
	
	doneCstlHnt: function(ret_code) {
		// End : call cb for cstl att done :  enxt cstl will be checked by monitor
		debug.log(em.hntmgr, ' Done 1 cstl !!! ', ret_code );
	
		// move next cstl. 
		em.cstlmgr.moveNextCstl();

	},
	
	allCstlHntDone: function() {
		
		debug.log(this, ' All cstl Auto Hnt Done @@@ ' );
		// UN- register  cstl move cb  for food change. 
		em.cbs.cstlmove1done.remove( this.cb_movedone);
		em.cbs.cstlwavedone.remove( this.cb_wavedone);
		
		this.dfd_cstlattdone.resolve();
		return;
	},
	
/*

	setParam: function ( autohnt_param ) {
			// store param 
		this.da_arr = autohnt_param.da_arr;
		this.cb_success =  autohnt_param.cb_success;
		this.cb_error = autohnt_param.cb_error;
		this.cb_notify = autohnt_param.cb_notify;
		
		this.cb_notify(10000, ' Done Set hnt mgr param');
	},*/

	
	
	// deffered !!! 
	// when done.. call resolve..  : 1 cstl... att . 
	startAutoHnt: function(autohnt_param) {
		
		var dfd = this.dfd_cstlattdone =  $.Deferred();
		
		if ( ! autohnt_param.DAsArr ) {
			console.log('Error !! Invalid set param : shoud provide DAsArr');
			dfd.reject();
			return dfd.promise();
		}
		
		
		debug.log(this, autohnt_param , " start !!! ");
		
		// store param	
		if (! this.DAsArr) {		// preserve prev DAs 
			// deep copy 
			this.DAsArr = autohnt_param.DAsArr.slice(0);
		}  
		
		this.cstlidx = autohnt_param.idx; 
	
		this.force_stop = false;		// 
		this.curDA = undefined;
		
		// register  cstl move cb  for food change. 
		var self = this;
		em.cbs.cstlmove1done.add(  this.cb_movedone = function() { self.after1CstlMove()} );		
		em.cbs.cstlwavedone.add( this.cb_wavedone = function() {self.allCstlHntDone();	});
 
			//  deep copy 
			// this.DAsArr = autohnt_param.DAsArr.slice(0);
		// this.sortDAs();
		var affordN = CDB.getCurUserOptions().affordN || 6000;
		var star;
		for (star = 0; star < this.DAsArr.length; star++ ) {		
			// sorting  . by distance
			var mine = em.cstlmgr.getCstlPos(0); 
			this.DAsArr[star].sort( function(a,b){ return CUtil.sortDistanceFn (a,b,mine); } ); 			
			
			// 여기서,,,  감당할 수 있는 N 이하로  filtering 수행함.  h, n  : no info <- remove . 
			this.DAsArr[star] =	this.DAsArr[star].filter ( function (el, index, array) { 
									if ( el.n > affordN ) return false;
									else if ( ! el.h  && ! el.n )  return false; 
									else return true;
									});
		}

		em.util.print_result(' --------  started... '  );
		
		this.startAutoAtt();
		
		return dfd.promise();
	},
	
/*
	// auto start.. co odi array 諛쏆쓬. 
	// 1 媛쒖뵫  att ?占쏀뻾.
	// cb ???占쎈씪?? next, or next cstl 占�?占쎌삤.
	// ???占쎌긽  ?占쎌쓣 寃쎌슦. wait ?占쏀뻾.  
	// break  = stop  ; pause, 吏�? 
	startAuto: function() {
	
		if ( ! this.da_arr ) {
			console.log('Error !! set param first ');
			return;
		}
		
				// reset  state ,, variables 
		this.force_stop = false;		// ?占쎄굅 cstl ?占쎌꽌 ?占쎈뒗?? ?占쎄린??da att stop ?占쎌뼱???? 
		this.min_returntime =0;
		this.max_returntime =0;
		
		// get start/end block index 
			

		// register  cstl move cb 
		em.cbs.cstlmove1done.add( this.after1CstlMove);		
			
		this.GetAttDAarr(this.da_arr);
		

	},
	*/


	startAutoAtt: function () {
		
		// this will call after move 
		debug.log(this, 'startAutoAtt gogo ');
		em.cstlmgr.moveCstlAt(this.cstlidx);
		
	},
	


	// 3rd revision  ------------------------------
	/*
		DA list 에서 선택
    먼저 first list 에서 20개
        h def 와 controlls 이용 검색
        skip 시마다 DA 에 skipcnt 증가
    안되면, second list 에서 20개 검색
        skip cnt  관리하고,  > 10 이면, pop
    못 찾으면,  cstl done 처리
        가장 낮은 h 이고,  더이상 찾을 이유 없음
    찾았다면, 이걸로 hnt 시도.
        error 이유가 없음
        만약 오류 나면, 뭔가 잘못된 경우
            cb data error code 파악 필요
            일단 오류니까, cstl done 처리
    set TA 시 att cnt 가 올라오는데, 
        att cnt 관리하고 , > 3 이면, pop
        이걸로 DA update
        da >=2  이면 마지막 try 이므로> list 에서 제거함
        cb 처리해야함.

	*/
	attProperDA: function() {
		debug.log(em.hntmgr, ' attProperDA !!!  ' );
		
		this.curH = em.cstlmgr.getbestH();
		var myO = em.cstlmgr.getSolnum(CDB.SOLS.OVER);
		var myB = em.cstlmgr.getSolnum(CDB.SOLS.BER);
		
		// eception handle 
		if ( this.curH === undefined ) {		// no heroe & no sols 
			debug.log(em.hntmgr, ' attProperDA :  ' , 'No avali Hs ');
			 this.doneCstlHnt(CHnting.NO_HERO);
			 return;
		}
		
		// check less min sols 
		if ( ( myO < 50 && ( CDB.getCurUserOptions().hntSols == 'Oonly' 
							|| ! CDB.getCurUserOptions().hntSols )) 
				||	// b!! check
				( myB < 50 &&  myO < 40 && CDB.getCurUserOptions().hntSols == 'O&B') 
			) {	
			debug.log(em.hntmgr, ' attProperDA :  ' , 'No overs   ' , myO, 'or less B',  myB);
			 this.doneCstlHnt(CHnting.LESS_SOLS);
			 return;
		}
 
 		debug.log(this, ' H:', this.curH, ' myO:', myO);
		
		// search proper DA in first array in range 20
		var self = this; 
		
		// END OF ARRAY check 
		var totallen =0;
		$.each(this.DAsArr, function(_,DA){ totallen += DA.length;});
		if ( totallen == 0) {
			// END OF ARRAY .. ALL DONE !!! 
			// call cb, log 
			
			// notify re-make DAsArr 
			
			debug.log(this, ' END OF ARRAY .. ALL DONE !!! ');
			em.accmgr.hntstate.setFlagRemakeDAsArr();
			this.doneCstlHnt(CHuntMgr2.ENDOF_DA_ARRAY);
			return ; 
		}
	
		// o & ber  att mode . choose less req DA ( i.e. easest !)
		var bEasest = (CDB.getCurUserOptions().hntSols == 'O&B');
			
		function findProperDA () {
			var properDA = undefined;
			$.each( self.DAsArr , function(i, DAs) {
					debug.log(this, ' TRY :::::::::::::  Find DA ARR:  ' , i );
					properDA =  self.attPossible(self.curH, DAs, myO, bEasest);
					if ( properDA ) { // found
						return false;	// exit each loop
						}
					// else try next DA arr  
			});
			
			return properDA; // not found  :: move to next cstl 
		}
		
		this.curDA = findProperDA();
		this.attDA_wDAinfo( this.curDA );
	},
	
	// h def, cons & da h , n 으로  가장 최적으 da 를 찾기  20 개 중.
	//   da 별    
	attPossible: function(h, DAs, myO, bEasest){
		var range = CDB.getCurUserOptions().DASearchRange ? CDB.getCurUserOptions().DASearchRange : 20 ;
		var max_control = h.c2;
		var bestDA = undefined;
		for (i=0; i < range && i < DAs.length; i++ ) {
			
			//set skip cnt 
			if( DAs[i].skipcnt === undefined) DAs[i].skipcnt = 0;
			 
			// check skip cnt  & att num 
			if ( DAs[i].skipcnt > GetSkipLimit()  
				|| DAs[i].disappered 
					|| ( ! DAs[i].h && ! DAs[i].n ) ) {	// no h, n info 
				DAs.splice(i,1);		// remove difficult DA & try next da
				continue; 
			}	
			
			// check att num : jump next 10 th  
			if ( DAs[i].attnum >= GetMaxAtt()) {	 
				DAs.splice(i,10);		// remove difficult DA & try next da
				continue; 
			}	
			
			var minO = CUtil.calcNeedO(h, DAs[i]);
			debug.log( this, 1, 'Check DA: ', 'x ', DAs[i].x , ' y:', DAs[i].y, ' h:', DAs[i].h , ' n:', DAs[i].n, ' atnum:', DAs[i].attnum, ' skip:', DAs[i].skipcnt );
			
			if ( max_control < minO ){
				DAs[i].skipcnt++;
				debug.log(this, 9999, 'try Next DA:  H-control ' +   max_control + ' is less (  req sol : ' +  minO , '--------------');
				continue;
			}
	
			// check cur number of castle soldi... 
			if ( minO > myO ) {
				DAs[i].skipcnt++;
	
				// try with berserk ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				if ( CDB.getCurUserOptions().hntSols == 'O&B' ) {
					debug.log(this, 1, ' mgr : try with berserk: ~~~~~~~~~~~~~~~~' );

					var myB = em.cstlmgr.getSolnum(CDB.SOLS.BER);
					debug.log(this, ' myB:', myB);
					var moreB = CUtil.calcMoreB(h, DAs[i], myO);
					if ( myB < moreB  ) {	// skip 
						debug.log(this, 1, ' More B: ', moreB, ' >>  MyB : ', myB , ' skip !!! try Next ------------');
						continue;
					}
					debug.log(this, 1, ' More B: ', moreB, ' <<   MyB : ', myB , ' Found !!!');
					// go hnt!! 
				} else {
					debug.log(this, 9999, 'try next DA:  Req Over num ' +  minO + ' > ' + ' barrack o : ' +  myO);
					debug.log( this, 'x ', DAs[i].x , ' y:', DAs[i].y, ' atnum:', DAs[i].attnum, ' skip:', DAs[i].skipcnt , '--------------------');
					continue;
				}
			}
			
			//  found da :  save proper on
			if ( ! bestDA) {
				bestDA = DAs[i];
				bestDA.minO = minO;
			} else {
				// cur DA needs more O  : choose  
				if ( ( bEasest && minO < bestDA.minO ) 
					|| ( minO >  bestDA.minO )  ){
					debug.log( this, 1,' Best DA : ' ,'x ', DAs[i].x , ' y:', DAs[i].y, ' h:', DAs[i].h , ' n:', DAs[i].n, ' atnum:', DAs[i].attnum, ' skip:', DAs[i].skipcnt );
					bestDA = DAs[i];
					bestDA.minO = minO;
				}
			}
			
		}
		
		return bestDA;
		
	},
	attDA_wDAinfo: function( dainfo) {
		
		// check  end arr or force stop 
		if (dainfo == undefined ) {
			debug.log ( this, ' Can not find Proper DA :  go next cstl ', this.curH, dainfo);
			// consider as all done !! 
			this.doneCstlHnt(CHuntMgr2.CANNOT_FIND_PROPERDA);
			// end of array stop !!! 
			return undefined;
		}
		
		if ( this.force_stop ) {
			console.log ( ' All done !!!');
			this.doneCstlHnt(0);	//  ret_code :: no mean
			return undefined;
		}
			 
		debug.log(em.hntmgr, ' attDA_wDAinfo !!!  ', dainfo );
		
		if (  dainfo.h ==undefined && dainfo.n == undefined ) {
			debug.log(em.hntmgr, ' no info H, N   ', dainfo );
			// go next DA 
			var self = this;
			setTimeout( function() { self.errCbAttda(CHnting.DA_INVALID); } , CUtil.RandTime(1000));
			return;
		}
				
		var ta_param = {};		
		ta_param.da = dainfo;
		ta_param.h = this.curH;
		ta_param.citnum = em.cstlmgr.curCstlID();
		
		debug.log(em.hntmgr, retName(this), 'DA param :  ', ta_param );
		
		this.hnting.setTgt(ta_param);
		this.hnting.doAttc();
	},



/*
	CSTL move CB 
*/


	after1CstlMove: function() {
			debug.log( em.hntmgr,  this, 'after1CstlMove :: ..   : start with get Sols '	);
			// start get sols first 
			setTimeout( function() { em.hntmgr.getSols(); }, CUtil.RandTime(0));
	},
	
	
/*
	.. move camp

GET /game/
soldier_educate_api.php?jsonpcallback=jsonp1323353477782&_=1323362536045&key=7c67cf5bf34d95dbf8c039a067a4619a
&city=22478
&_l=en&_p=EW-DROID HTTP/1.1

jsonp1323353477782({"code":0,"ret":{"soldiers":[[1,100,1],[2,43,1],[3,0,0],[4,0,0],[5,0,0],[6,0,0]],
"space":2857,"head":703,"def":1,"next":[7,7],"f":-140}})
*/

	getSols: function() {
		debug.log(this,  'after1CstlMove :: ..get sols'	);
		var self = this;
		var jcb = $.Callbacks();
		
		jcb.add( function (data) {
			debug.log(self, 'sols ', data);
			if(data.code == 0 && data.ret ) {
				// update solders & go next step : get heroes 
				 em.cstlmgr.updateSols(data.ret.soldiers);
				 self.getHeroes();
			} else {
				// error !! : ??? why? 
				// no barrack !!!   code 2303
				debug.log(self, 'GOT sols error : done cstl..  ', data.code);
				self.doneCstlHnt(CHnting.LESS_SOLS);
				return;	
			}
			 
		});
		em.tasks.getSols(jcb);
	},
	
	/*
		GET /game/
gen_conscribe_api.php?jsonpcallback=jsonp1323353477774&_=1323362178550&key=7c67cf5bf34d95dbf8c039a067a4619a
&city=22478
&action=gen_list
&_l=en&_p=EW-DROID HTTP/1.1

jsonp1323353477774({"code":0,"ret":{"hero":[
{"id":87588,"gid":185,"p":9,"i":27,"c1":12,"f":50,"g":6,"c2":407,"fy":0,"s":5,"e":9,"w":0,"tw":0,"tl":0,"ex":1069,"te":2267,"np":0,"ni":0,"nc1":0,"nc2":0,"ns":0,"ncd":0,"pr":18000}]}})

	*/
	getHeroes: function() {
		debug.log(this,  'after1CstlMove :: ..get getHeroes '	);
		var self = this;
		var jcb = $.Callbacks();
		
		jcb.add( function (Harr) {
			//data is h array 1!!
			debug.log(self, 'heroes :', Harr);
			// if(data.code == 0 && data.ret ) {
			if( Harr ) {
				// update solders & go next step : get heroes 
				 em.cstlmgr.updateAllHs(Harr);
				 
				// TODO : go next action 
				 self.tryExchangeF();
			} else {
				// error !! : ??? why? 
			}
			 
		});
		em.tasks.getHeroes(jcb);
	},
	
	tryExchangeF: function() {
			debug.log(this,  'after1CstlMove :: ..  try exchange food '	);
			// if less than req food :  exchange food
			var min_food = CDB.getUserMinFood();
			var cstlinfo = em.cstlmgr.getCurCstl();

			debug.log(this,  'min_food ,  cstlinfo.res.f' ,  min_food, cstlinfo.res.f) ;
			// TODO : exchange �?task �??�동. 
									// use action helper
			var g2f_amount = CDB.getUserG2Famount();//50*10000;
			// decide  g 2 f amount : 50 �?, if <  , all 
			if ( cstlinfo.res.g < g2f_amount) {
				g2f_amount = Math.round(cstlinfo.res.g *( 2/3));
			}
			if ( cstlinfo.res.g < 5000 ) g2f_amount = 0; // don t exchange 
			
			if ( cstlinfo.res.g > 0 && g2f_amount > 0 
					&&  cstlinfo.res.f < min_food ) { // 999 * 8 th 
					
				// set result cbs
				debug.log(this,  'gogo  exchange food !!', g2f_amount) ;
				
				var self = this;
				em.tasks.exchangeRes( g2f_amount, 0, 0 ,
					// done cb 
					 function() {	 
							debug.log(self, " EXchange food :: success CB is called !!! ") ;
							// res is already updated by tasks 
							setTimeout( function() { self.attProperDA(); }, CUtil.RandTime(1500));
						} 
/*
					cbs = {
						success_cb : function(code, msg) {
							debug.log(self, " EXchange food :: success CB is called !!! ") ;
							// res is already updated by tasks 
							setTimeout( function() { self.attProperDA(); }, CUtil.RandTime(1000));
						}, 
						error_cb : function(errorcode) {
							debug.log(self, " EXchange : Erro CB is called !!! in test case :" + errorcode) ;
						},
						notify_cb : function(code, msg) {
							em.util.print_result("TASKS " + code + msg );
						}, 
					}*/

					);
			}	
			else  {
				// 바로 next action start 
				setTimeout( function() { em.hntmgr.attProperDA(); }, CUtil.RandTime(1000));
			}
	},
	
	
		/*
		==============================================
		make DA Array with Favs 
	*/
/*
		{"favs":[
	[31205,149,49,1,3],
	[43720,183,58,1,3],
	*/
/*
	sortDAs: function() {
		console.log('sortDAs in hntmgr 2222');
		

		// sort 
		var star;
		for (star = 0; star < this.DAsArr.length; star++ ) {
			
			// sorting  . by distance
			var mine = em.cstlmgr.getCstlPos(0); 
			var my_x = mine.x; 
			var my_y = mine.y;
			debug.log( this, ' Sort DAs ::',  my_x, my_y, star) ;
			this.DAsArr[star].sort(function(a,b){
				
					//  max 泥섎━ .!!!   10 <- 280 - > 260 :  30 !! 
					// 10 - 260  ; 250 ,   280 - 250 : 30  ,  min ( 250, 30)
					//  50 , 80 : 50 -80 : 30,    280 - 30 = 250 ; 
					// 160, 280 : 120 ,  280 - 120 : 160 
					var diff_ay = Math.min( Math.abs(my_y -a.y) ,  280 - Math.abs(my_y - a.y)  );
					var diff_ax = Math.min( Math.abs(my_x -a.x) ,  280 - Math.abs(my_x - a.x)  );

					var diff_by = Math.min( Math.abs(my_y -b.y) ,  280 - Math.abs(my_y - b.y)  );
					var diff_bx = Math.min( Math.abs(my_x -b.x) ,  280 - Math.abs(my_x - b.x)  );
					
					var dis_a = Math.pow(diff_ax,2) + Math.pow( diff_ay, 2) ;
					var dis_b = Math.pow(diff_bx,2) + Math.pow( diff_by, 2) ;
					
					// var dis_a = Math.pow(Math.abs(my_x - a.x ),2) + Math.pow( Math.abs(my_y- a.y), 2) ;
					// var dis_b = Math.pow(Math.abs(my_x - b.x ),2) + Math.pow( Math.abs(my_y- b.y), 2) ;
					return dis_a - dis_b;
				}); 
		}	
		
		console.log(' sorted Favs DAs :', this.DAsArr);

	},*/

	
	
	

	
	SetStop: function() {
		this.force_stop = true;
		debug.log(self,'Set ForceStop ::' , this.force_stop);
	},
	
	abort: function(){
			// stop !! 
			debug.log(em.hntmgr, 'cb ret error : stop !!  ' );
			var error_code = 1;
			this.cb_error(error_code);
	},
	
	
	
	/*
		 util function 
	*/
	
};

